<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}

    <script type="text/javascript" src="/static/js/Calendar.js"></script>
    <script type="text/javascript" src="https://mapapi.qq.com/web/mapComponents/geoLocation/v/geolocation.min.js"></script>
    <script charset="utf-8" src="https://map.qq.com/api/gljs?libraries=tools&v=1.exp&key=Y5IBZ-WT4KU-OLYVW-B77GD-IBUUJ-OFFDZ"></script>
</head>
<body>
<style>
    html, body {
        background-color: #FFF !important;
    }

    .modal-body {
        background-color: #fff;
        padding: 15px
    }

    .page-header {
        margin-top: 15px !important;
    }

    .add_button {
        border-top: 1px solid #eee;
        padding-top: 15px;
    }

    .config_img {
        height: 65px;
        margin-top: 15px;
    }

    .layui-form-pane .layui-form-label {
        font-size: 12px !important;
    }

    .modal-body {
        display: inline-block;
        padding-bottom: 78px;
    }
    #tip{
        z-index: 9999;
        width:230px;padding-right:0px!important;
        position: absolute;
        top:20px;
        right:20px;
        z-index:9999;
    }
    #tip input{border:1px solid #e3e3e3;line-height:25px;padding:0px 5px}
    #tip span{background-color:#0b6fff;line-height:27px;display: inline-block;float: right;color: #FFFFFF;padding:0px 10px}
    .searachList{
        width:230px;
        background-color: #fff;
        padding-left: 10px;
        position: absolute;
        font-size: 12px;
        right:20px;
        top:44px;
        border-radius: 3px;
        border: 1px solid #ccc;
        z-index:9998;
        max-height:200px;
        overflow: hidden;overflow-y: auto;
    }
    .searachList span{
        width:100%;
        display: inline-block;
        line-height:25px;
    }
    .searachList .list{
        border-bottom: 1px #cccccc dashed;
        display: inline-block;width:100%;
    }
    .geographic input{width:100px!important;float: left;margin-right:15px;}
</style>

<div class="modal-body">

    <fieldset class=" layui-field-title">

        {if condition="$detail.id>0"}
           <legend>编辑企业</legend>
        {else/}
           <legend>添加企业</legend>
        {/if}
    </fieldset>


    <form class="layui-form layui-form-pane form-horizontal" action="" name="layui-form">
        <div class="layui-form-item layui-col-md4">
            <label class="layui-form-label">*企业名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" placeholder="企业名称" class="layui-input" value="{$detail.title}">
            </div>
        </div>

        <!--地图标点-->
        <div class="layui-form-item">
            <label class="layui-form-label wd-110">地图标识:</label>
            <div class="col-sm-5 geographic">
                <input type="hidden" class="form-control" name="lng" id="lng"  value="{$detail.lng}" >
                <input type="hidden" class="form-control" name="lat" id="lat" value="{$detail.lat}" >
            </div>
        </div>

        <div class="layui-form-item" style="position: relative;width:600px;margin-left:60px;">
            <div id="container" class="map" tabindex="0" style="height:300px;width:100%;"></div>
            <div id='tip'>
                <input type="text" id="search" value="" placeholder="输入关键字搜索地址"/>
                <span>搜索</span>
            </div>
            <div class="searachList"></div>
        </div>

        <div id="info" style="display: none">
            <h4 id="txt"></h4>
            <p>当前中心点：<span id="position"></span></p>
        </div>
        <!--地图标点-->

        <div class="layui-form-item layui-col-md4">
            <label class="layui-form-label">缩略图:</label>
            <div class="layui-col-md7">
                <div class="input-group ">
                    <input type="hidden" id="thumb" name="thumb" class="layui-input" autocomplete="off"
                           value="{$detail.thumb}">
                    <span class="input-group-btn">
                        <button class="btn btn-default" id="upload" type="button" data-original-title=""
                                title="">选择图片</button>
                    </span>
                </div>

                {if condition="$detail['thumb'] eq ''"}
                <img class="config_img thumb" src="/static/images/nopic-107.png">
                {else/}
                <img class="config_img thumb" src="{$detail.thumb}">
                {/if}
            </div>
        </div>

        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label">责任单位</label>
            <div id="duty_unit" class="demo-transfer"></div>
        </div>

        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label">责任人</label>
            <div id="duty_person" class="demo-transfer"></div>
        </div>
<!--        {if condition="$detail['menuTop'] eq 2" }style="display: none" {/if}-->
        <div class="layui-form-item layui-col-md12 leader_val"  >
            <label class="layui-form-label">服务领导</label>
            <div id="leader" class="demo-transfer"></div>
        </div>

        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label ">一级分类</label>
            <div class="layui-col-md2">
                <select name="menuTop" lay-verify="menuTop" lay-filter="menuTop">
                    <option value="0">请选择</option>
                    {volist name="pro_type" id="vo"}
                    <option value="{$key}" {if condition="$detail['menuTop'] eq $key" } selected {/if}>{$vo}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label">企业类型</label>
            <div class="layui-col-md2">
                <select name="enterprise">
                    <option value="0">请选择一级分类</option>
                    {volist name="enterprise" id="vo" }
                    <option value="{$vo.value}" {if condition="$detail['enterprise'] eq $vo.value" } selected {/if}>{$vo.title}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-col-md12 cultivation" {if condition="$detail['menuTop'] neq 1" }style="display: none" {/if}>
            <label class="layui-form-label">培育类别</label>
            <div class="layui-col-md2">
                <select name="cultivation">
                    <option value="0">请选择</option>
                    {volist name="cultivation" id="vo"}
                    <option value="{$key}" {if condition="$detail['cultivation'] eq $key" } selected {/if}>{$vo}</option>
                    {/volist}
                </select>
            </div>

            <a class="layui-form-label layui-col-md-offset1" title="企业秘书及联系电话" href="javascript:;">企业秘书及联系电话:</a>
            <div class="input-group layui-col-md2" style="float: left">
                <input type="text" class="layui-input" name="agent" placeholder="企业秘书及联系电话" value="{$detail.agent}" >
            </div>
        </div>
 <!--{if condition="$detail['menuTop'] neq 2" }style="display: none" {/if}-->
<div class="layui-form-item layui-col-md12 condition">
<label class="layui-form-label">企业状况</label>
<div class="layui-col-md2">
    <select name="condition_val">
        <option value="0">请选择</option>
        <option value="1" {if condition="$detail['condition_val'] eq 1" } selected {/if} >运行正常企业</option>
        <option value="2" {if condition="$detail['condition_val'] eq 2" } selected {/if}>困难企业</option>
        <!--<option value="3" {if condition="$detail['condition_val'] eq 3" } selected {/if}>特别困难企业</option>-->
        <option value="4" {if condition="$detail['condition_val'] eq 4" } selected {/if}>停产企业</option>
    </select>
</div>
</div>

<div class="layui-form-item layui-col-md12">
    <label class="layui-form-label">运营情况</label>
    <div class="layui-col-md2">
        <select name="operation">
            <option value="0" {if condition="$detail['operation'] eq 0" } selected {if}>请选择</option>
            <option value="1" {if condition="$detail['operation'] eq 1" } selected {/if}>正常</option>
            <option value="2" {if condition="$detail['operation'] eq 2" } selected {/if}>异常</option>
        </select>
    </div>


    <label class="layui-form-label layui-col-md-offset1"><a href="javascript:;" title="企业联系人及电话">企业联系人及电话</a></label>
    <div class="layui-col-md2">
        <input type="text" name="project_chief" class="layui-input test-item1" placeholder="企业联系人及电话"  value="{$detail.project_chief}">
    </div>
</div>


<div class="layui-form-item layui-col-md12 progress_val" {if condition="$detail['menuTop'] eq 1" }style="display: none" {/if}>
    <label class="layui-form-label"><a href="javascript:;" title="组长">组长</a></label>
    <div class="layui-col-md2">
        <input type="text" name="chargeman" class="layui-input test-item1" placeholder="组长"
               value="{$detail.chargeman}">
    </div>

    <label class="layui-form-label layui-col-md-offset1"><a href="javascript:;" title="成员">成员</a></label>
    <div class="layui-col-md2">
        <input type="text" name="member" class="layui-input test-item1" placeholder="成员"
               value="{$detail.member}">
    </div>
</div>


<div class="layui-form-item layui-col-md12">
    <label class="layui-form-label"><a href="javascript:;" title="联络员及电话">联络员及电话</a></label>
    <div class="layui-col-md2">
        <input type="text" name="liaison" class="layui-input test-item1" placeholder="联络员及电话"
               value="{$detail.liaison}">
    </div>

    <label class="layui-form-label layui-col-md-offset1"><a href="javascript:;" title="走访时间">走访时间</a></label>
    <div class="layui-col-md2">
        <input type="text" name="visit_time" class="layui-input test-item1" placeholder="走访时间"
               onClick="new Calendar().show(this);" value="{$detail.visit_time}">
    </div>
</div>


<!--<div class="layui-form-item layui-col-md12 progress_val" {if condition="$detail['menuTop'] neq 2" }style="display: none" {/if} >-->
<!--<label class="layui-form-label">本月走访次数</label>-->
<!--<div class="input-group col-xs-2" style="float: left">-->
    <!--<input type="text" class="layui-input" name="progress" placeholder="本月走访次数" value="{$detail.progress}">-->
<!--</div>-->

<!--<label class="layui-form-label layui-col-md-offset1">本年走访次数</label>-->
<!--<div class="input-group col-xs-2" style="float: left">-->
    <!--<input type="text" class="layui-input" name="year_progress" placeholder="本年走访次数" value="{$detail.year_progress}">-->
<!--</div>-->
<!--</div>-->


<div class="layui-form-item layui-col-md12 leader_val" {if condition="$detail['menuTop'] eq 2" }style="display: none" {/if}>
    <label class="layui-form-label"><a href="javascript:;" title="所属行业">所属行业</a></label>
    <div class="layui-col-md2">
        <input type="text" name="industry" class="layui-input test-item1" placeholder="所属行业"
               value="{$detail.industry}">
    </div>

    <label class="layui-form-label layui-col-md-offset1"><a href="javascript:;" title="主要产品">主要产品</a></label>
    <div class="layui-col-md2">
        <input type="text" name="product" class="layui-input test-item1" placeholder="主要产品"
               value="{$detail.product}">
    </div>
</div>

<div class="layui-form-item layui-col-md12 leader_val" {if condition="$detail['menuTop'] eq 2" }style="display: none" {/if}>
    <label class="layui-form-label"><a href="javascript:;" title="累计应税收入">累计应税收入</a></label>
    <div class="layui-col-md2">
        <input type="text" name="revenue" class="layui-input test-item1" placeholder="累计应税收入"
               value="{$detail.revenue}">
    </div>

    <label class="layui-form-label layui-col-md-offset1"><a href="javascript:;" title="拟进规时间">拟进规时间</a></label>
    <div class="layui-col-md2">
        <input type="text" name="gauge" class="layui-input test-item1" placeholder="拟进规时间"    onClick="new Calendar().show(this);"
               value="{$detail.gauge}">
    </div>
</div>


<!--图文模型&单页模型-->
<div class="layui-form-item">
    <a class="layui-form-label" title="走访情况" href="javascript:;">*走访情况:</a>
    <div class="layui-col-md6">
        <textarea id="content">{$detail.content}</textarea>
    </div>
</div>


<div class="layui-form-item">
    <a class="layui-form-label" title="存在的问题" href="javascript:;">存在的问题:</a>
    <div class="layui-col-md6">
        <textarea name="visit_remark" class="layui-textarea">{$detail.visit_remark}</textarea>
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">备注:</label>
    <div class="layui-col-md6">
        <textarea name="remark" placeholder="备注" class="layui-textarea">{$detail.remark}</textarea>
    </div>
</div>

<input type="hidden" name="id" value="{$detail.id}">
<input type="hidden" name="library" value="{$library}">
</form>

</div>
<div class="add_button">
    <div class="layui-form-item">
        <div class="layui-col-md-offset1">
            <!--<a type="button" class="layui-btn layui-btn-primary"  href="{:URL('project/index/index')}?library={$library}">取消</a>-->
            <button type="button" class="layui-btn layui-btn-primary" onclick="window.history.go(-1);" >取消</button>
            <button type="button" class="layui-btn" id="newsave">保存</button>
        </div>
    </div>
</div>
<script src="/static/js/location2.js"></script>
<script>
    var library = {$library};
    var newModal = new yii.modal();
    layui.extend({
        tinymce: '/static/tinymce/tinymce'
    });
    layui.use(['form', 'tinymce', 'laydate', 'transfer'], function () {
        var form = layui.form
            , layer = layui.layer;
        var tinymce = layui.tinymce;
        var transfer = layui.transfer;
        //责任单位
        var duty_unit = {$duty_unit};
        var account = {$account};
        //责任单位
        transfer.render({
            elem: '#duty_unit'
            , id: 'duty_unit'
            , data: duty_unit
            , title: ['全选', '全选']
            , showSearch: true
            , height: 200
            , value: {$duty_unit_k}
        }),

            //显示搜索框
            transfer.render({
                elem: '#duty_person'
                , id: 'duty_person'
                , data: account
                , title: ['全选', '全选']
                , showSearch: true
                , height: 200
                , value: {$duty_person_k}
            }),

            //显示搜索框
            transfer.render({
                elem: '#leader'
                , id: 'leader'
                , data: account
                , title: ['全选', '全选']
                , showSearch: true
                , height: 200
                , value: {$leader_k}
            })


        tinymce.render({
            elem: '#content',
            height: 600,
            images_upload_handler: function (blobInfo, succFun, failFun) {
                var xhr, formData;
                var file = blobInfo.blob();//转化为易于理解的file对象
                xhr = new XMLHttpRequest();
                xhr.withCredentials = false;
                xhr.open('POST', "{:URL('/common/upload/textUpload')}");
                xhr.onload = function () {
                    var json;
                    json = JSON.parse(xhr.responseText);
                    succFun(json.path);
                };
                formData = new FormData();
                formData.append('file', file, file.name);//此处与源文档不一样
                xhr.send(formData);
            }
        }, (opt, edit) => {
        });

        function eachvalue(data) {
            var newvalue = '';
            $.each(data, function (index, value) {
                newvalue += value.title + ";";
            });
            return newvalue;
        };

        //触发二级联动
        form.on('select(menuTop)', function (data) {
            //触发联动
            var id = data.value;

            if (id == 1) {
                $(".cultivation").show();
                // $(".condition").hide();
                $(".progress_val").hide();
                $(".leader_val").show()
            } else {
                $(".cultivation").hide();
                // $(".condition").show();
                $(".progress_val").show();
                $(".leader_val").hide()
            }

            $.ajax({
                type: 'post',
                url: "{:URL('project/Communal/selType')}",
                data: {menuTop: id},
                dataType: 'JSON',
                success: function (res) {
                    var arr = res.list;
                    var html = '<option value="">请选择</option>';
                    $.each(arr, function (e, v) {
                        html += '<option value="' + v.id + '">' + v.name + '</option>';
                    });
                    $('select[name="enterprise"]').html(html);
                    form.render('select');
                },
                error: function (res) {
                }
            });

        });


        $("#newsave").click(function () {
            var content = tinymce.get('#content').getContent();
            var duty_unit = transfer.getData('duty_unit');
            var duty_person = transfer.getData('duty_person');
            var leader = transfer.getData('leader');
            var leader_v = eachvalue(leader);
            var duty_unit_v = eachvalue(duty_unit);
            var duty_person_v = eachvalue(duty_person);
            var data = $("form[name='layui-form']").serializeArray();
            data.push({name: "content", value: content});
            data.push({name: "duty_person", value: duty_person_v});
            data.push({name: "duty_unit", value: duty_unit_v});
            data.push({name: "leader", value: leader_v});
            $.ajax({
                type: 'post',
                url: "{:URL('project/index/save')}",
                data: data,
                dataType: 'JSON',
                success: function (res) {
                    if (res.code != 0) {
                        layer.alert(res.msg);
                    } else {
                        window.history.go(-1);
                        // window.location.href = "{:URL('project/index/index')}?library=" + library;
                    }
                },
                error: function (res) {
                }
            });
        });

        layui.form.render('select');
        form.render();
    });


    //文件页面
    $("#upload").click(function () {
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/upload/index')}",
            type: "post",
            data: {
                type: 'detail'
            }
        });
    });

    newModal.on("upload", function (data) {
        var images = '';
        $(newModal.getid()).find("#data-area .newimages .active img").each(function () {
            images = $(this).attr('src');
            return false
        })
        $(newModal.getid()).hide();
        //$(".modal-backdrop").remove();
        //$('#nowMainProjectDataForm').modal('hide');
        $(newModal.getid()).find(".modal").hide();
        $("#thumb").val(images);
        $(".config_img").attr("src", images)
    });
</script>

</body>
</html>